import axios from 'axios'
import Vue from 'vue'
import { Toast } from 'vant'

axios.defaults.baseURL = 'http://itfly.vip:8888'

// 响应拦截 在你请求到数据之前先做处理
axios.interceptors.response.use((res) => {
  console.log(res);
  return res
}, err => {
  Toast(err)
  Promise.reject(err)
})

Vue.prototype.$http = {
  async getLunbo(params) {
    return await axios.get('/api/getlunbo', params)
  },
  async getGrids(params) {
    return await axios.get('/api/grids', params)
  },
  async getNewsList(params) {
    return await axios.get('/api/getnewslist', params)
  },
  async getNewsInfo(params) {
    return await axios.get('/api/getnew/' + params)
  },
  /**
   * 
   * @param {id} 请求的ID
   * @param {pageNo} 页码
   * @param {pageSize} 每一页条数 
   * @returns 
   */
  async getComments({ id, pageNo, pageSize = 3 }) {
    return await axios.get(`/api/getcomments/${id}?pageindex=${pageNo}&limit=${pageSize}`)
  },
  async addComments({ id, content }) {
    return await axios.post(`/api/postcomment/${id}`, { content })
  }
}